//
//  XZGPasswordViewController.m
//  FastDoctor
//
//  Created by xiangzhigang on 16/5/22.
//  Copyright © 2016年 xiangzhi gang. All rights reserved.
//

#import "XZGPasswordViewController.h"
#import <SVProgressHUD/SVProgressHUD.h>
#import "NQSaveTool.h"

@interface XZGPasswordViewController (){
    UITextField *password1;
    UITextField *password2;

}

@end

@implementation XZGPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    self.navigationController.navigationBarHidden = NO;
    self.title = @"设置密码";
    self.view.backgroundColor = [UIColor colorWithRed:240/255.0f green:240/255.0f blue:240/255.0f alpha:1];
;
    
    UIButton *next = [[UIButton alloc]initWithFrame:CGRectMake(50, 220, self.view.frame.size.width - 100, 30)];
    [next setTitle:@"完成" forState:UIControlStateNormal];
    next.backgroundColor = NQNavColor;
    next.layer.cornerRadius = 5.0f;
    [next setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [next addTarget:self action:@selector(clickOve) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:next];
    
    
    [self createTextFields];
}

- (void)clickOve {
    if (password1.text.length < 2) {
        [SVProgressHUD showErrorWithStatus:@"请输入2位及以上密码"];
        return;
    }
    if (![password1.text isEqualToString:password2.text]) {
        [SVProgressHUD showErrorWithStatus:@"两次输入密码不符"];
    } else {
        //保存密码
        [NQSaveTool setObject:password1.text forKey:NQpassWord];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}
//密码文本框创建
- (void)createTextFields {
    password1 = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, self.view.frame.size.width - 100, 40)];
    password1.placeholder = @"请输入密码";
    password1.borderStyle = UITextBorderStyleRoundedRect;
    password1.clearButtonMode = UITextFieldViewModeWhileEditing;
    password1.secureTextEntry=YES;
    [self.view addSubview:password1];
    
    
    password2 = [[UITextField alloc] initWithFrame:CGRectMake(50, 150, self.view.frame.size.width - 100, 40)];
    password2.placeholder = @"请再次输入密码";
    password2.borderStyle = UITextBorderStyleRoundedRect;
    password2.clearButtonMode = UITextFieldViewModeWhileEditing;
    password2.secureTextEntry=YES;
    [self.view addSubview:password2];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
